<?php

    if (!class_exists('shopObject')) {
        require(CORE_INCLUDE_DIR.'/shopObject.php');
    }

    class mdl_track extends shopObject
    {
        var $idColumn = 'id';
        var $textColumn = 'id';
        var $adminCtl = 'plugins/track';
        var $defaultCols = 'express_id,op_time,op_msg,status,createtime,uptime';
        var $defaultOrder = array('id','ASC');
        var $tableName = 'sdb_express_manager_track';
        var $hasTag = true;
        var $schemaIdent = 'track';

        function &_columns(){
            $schema = &$this->system->loadModel('utility/schemas');
            $table = substr($this->tableName,4);
            $schema_file = dirname(__FILE__).'/dbschema/'.$this->schemaIdent.'.php';
            if(is_file($schema_file)){
                $define = require($schema_file);
                $this->__table_define = &$db[$this->schemaIdent]['columns'];
            }
            return $this->__table_define;
        }

        function getColumns($filter,$from = null)
        {
            $col = parent::getColumns();
            $command_file = dirname(__FILE__).'/view/admin/track/finder_command.html';
            $col['_cmd'] = array('label'=>__('操作'),'width'=>75,'html'=>$command_file);
            return $col;
        }

        function searchOptions()
        {
            $column = parent::searchOptions();
            return $column;
        }

        function getFieldById($id,$aField=array('*'))
        {
            $sql = 'SELECT '.implode(',',$aField).' FROM '.$this->tableName.' WHERE id='.$id;
            $row = $this->db->selectrow($sql);
            return $row;
        }

        function getTrackInfoByExpressId($express_id,$aField=array('*'))
        {
            $sql = 'SELECT '.implode(',',$aField).' FROM '.$this->tableName.' WHERE express_id="'.$express_id.'" AND disabled="false"';
            $sql .= ' ORDER BY op_time';
            $data = $this->db->select($sql);
            return $data;
        }

        function save($data)
        {
            if ($data['id']) {
                $rs = $this->db->exec('SELECT * FROM '.$this->tableName.' WHERE id='.$data['id']);
                $sql = $this->db->GetUpdateSql($rs,$data);
            } else {
                $rs = $this->db->exec('SELECT * FROM '.$this->tableName.' WHERE 0=1');
                $sql = $this->db->GetInsertSql($rs,$data);
            }
            return $this->db->exec($sql);
        }
    }


?>